<template>
    <el-card>
        <DoctorSearch @add-doctor="handleAddDoctor" @search="handleSearch" @export="handleExport" />
        <DoctorForm ref="doctorFormRef" :search-params="searchParams" @view-detail="handleViewDetail"
            @edit="handleEdit" />
    </el-card>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import DoctorForm from './DoctorForm.vue'
import DoctorSearch from './DoctorSearch.vue'

// 定义事件
const emit = defineEmits(['view-detail', 'edit'])

// 搜索参数
const searchParams = ref({})

// 表格组件引用
const doctorFormRef = ref()

// 处理新增医生
const handleAddDoctor = () => {
    console.log('新增医生 - 跳转到新增页面')
    // TODO: 路由跳转到新增医生页面
}

// 处理搜索
const handleSearch = (params: any) => {
    searchParams.value = params
    // 触发表格刷新
    if (doctorFormRef.value) {
        doctorFormRef.value.searchDoctors()
    }
}

// 处理导出
const handleExport = () => {
    console.log('导出数据')
    // TODO: 实现导出功能
}

// 处理查看详情
const handleViewDetail = (row: any) => {
    console.log('查看医生详情 - 传递给父组件:', row)
    emit('view-detail', row)
}

// 处理编辑医生
const handleEdit = (row: any) => {
    console.log('编辑医生 - 传递给父组件:', row)
    emit('edit', row)
}
</script>

<style scoped>
.el-card {
    width: 1150px;
    margin: 0 auto;
}
</style>